package com.gujia.concurrent.barrier;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class CityThread implements Runnable{

    private Counter counter;
    private String city;
    private CyclicBarrier barrier;


    public CityThread(Counter counter, String city, CyclicBarrier barrier) {
        this.counter = counter;
        this.city = city;
        this.barrier = barrier;
    }

    @Override
    public void run() {
        this.counter.cityCount(city);

        try {
            //阻塞的等待其他线程
            this.barrier.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (BrokenBarrierException e) {
            e.printStackTrace();
        }
    }
}
